<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="职务级别名称">
              <j-input placeholder="请输入职务级别名称" v-model="queryParam.levelName"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="职务级别代码">
              <j-input placeholder="请输入职务级别代码" v-model="queryParam.levelCode"></j-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="职务级别序号">
                <j-input placeholder="请输入职务级别序号" v-model="queryParam.levelIndex"></j-input>
              </a-form-item>
            </a-col> -->
            <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="状态">
                <j-dict-select-tag placeholder="请选择状态" v-model="queryParam.status" dictCode="ENABLE_OR_DISABLE"/>
              </a-form-item>
            </a-col> -->
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus" :disabled="isDisabledAuth('erpOrgPositionLevel:add')">新增
      </a-button>
      <!-- <a-button type="primary" icon="download" @click="handleExportXls('职务级别')"
                :disabled="isDisabledAuth('erpOrgPositionLevel:export')">导出
      </a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"
                @change="handleImportExcel">
        <a-button type="primary" icon="import" :disabled="isDisabledAuth('erpOrgPositionLevel:import')">导入</a-button>
      </a-upload> -->
      <!-- 高级查询区域 -->
      <!--<j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel" :disabled="isDisabledAuth('erpOrgPositionLevel:delete')">
            <a-icon type="delete"/>
            删除
          </a-menu-item>
          <a-menu-item key="2" @click="batchSubmit" :disabled="isDisabledAuth('erpOrgPositionLevel:submit')">
            <a-icon type="to-top"/>
            提交
          </a-menu-item>
          <a-menu-item key="3" @click="batchAudit" :disabled="isDisabledAuth('erpOrgPositionLevel:audit')">
            <a-icon type="audit"/>
            审核
          </a-menu-item>
          <a-menu-item
            key="4"
            @click="batchCounterTrial"
            :disabled="isDisabledAuth('erpOrgPositionLevel:counterTrial')">
            <a-icon type="rollback"/>
            反审
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12" :key="index">
                    <a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox>
                  </a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;">
          <a-icon type="setting" :style="iconStyle"/>
        </a>
      </a-popover>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
          style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
        <template slot="status" slot-scope="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">

          <template v-if="record.auditStatus==0">
            <a-button
              class="ruleButton"
              :ghost="true"
              type="primary"
              icon="edit"
              @click="handleEdit(record)"
              :disabled="isDisabledAuth('erpOrgPositionLevel:edit')"
            />
            <a-divider type="vertical"/>
            <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
              <a-button
                class="ruleButton"
                :ghost="true"
                type="primary"
                icon="delete"
                :disabled="isDisabledAuth('erpOrgPositionLevel:delete')"/>
            </a-popconfirm>
            <a-divider type="vertical"/>
            <a-popconfirm title="确定提交吗?" @confirm="() => handleSubmit(record.id)">
              <a-button
                type="primary"
                size="small"
                :disabled="isDisabledAuth('erpOrgPositionLevel:submit')">提交</a-button>
            </a-popconfirm>

          </template>
          <template v-if="record.auditStatus==1">
            <a-button
              type="primary"
              size="small"
              @click="handleAudit(record.id)"
              :disabled="isDisabledAuth('erpOrgPositionLevel:audit')">审核</a-button>
          </template>
          <template v-if="record.auditStatus==2">
            <a-popconfirm title="确定反审吗?" @confirm="() => handleCounterTrial(record.id)">
              <a-button
                type="primary"
                size="small"
                :disabled="isDisabledAuth('erpOrgPositionLevel:counterTrial')">反审</a-button>
            </a-popconfirm>
          </template>
        </span>

      </a-table>
    </div>

    <erp-org-position-level-modal ref="modalForm" @ok="modalFormOk"></erp-org-position-level-modal>
    <audit-modal ref="auditModal" @ok="modalFormOk"></audit-modal>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import ErpOrgPositionLevelModal from './modules/ErpOrgPositionLevelModal'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'

export default {
  name: 'ErpOrgPositionLevelList',
  mixins: [JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
  components: {
    ErpOrgPositionLevelModal
  },
  data() {
    return {
      description: '职务级别管理页面',
      // 表头
      columns: [],
      // 列设置
      settingColumns: [],
      // 列定义
      defColumns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '职务级别名称',
          width: 300,
          align: 'center',
          dataIndex: 'levelName'
        },
        {
          title: '职务级别代码',
          width: 300,
          align: 'center',
          dataIndex: 'levelCode'
        },
        {
          title: '职务级别序号',
          width: 200,
          align: 'center',
          dataIndex: 'levelIndex'
        },
        // {
        //   title: '状态',
        //   align: 'center',
        //   dataIndex: 'status_dictText',
        // },
        {
          title: '描述',
          align: 'center',
          width: 400,
          dataIndex: 'description'
        },
        {
          title: '审核状态',
          align: 'center',
          dataIndex: 'auditStatus_dictText',
          scopedSlots: { customRender: 'status' },
          // fixed: 'right',
          filterMultiple: false,
          filters: [
            {
              text: '待提交',
              value: 0
            }, {
              text: '待审核',
              value: 1
            }, {
              text: '已审核',
              value: 2
            }]
        },
        /*  {
            title:'是否已删除',
            align:"center",
            dataIndex: 'delFlag_dictText',
          }, */
        /* {
          title:'经办人编号',
          align:"center",
          dataIndex: 'handlerId',
        },
        {
          title:'经办人部门ID',
          align:"center",
          dataIndex: 'handlerDeptId',
        },
        {
          title:'经办人部门编码',
          align:"center",
          dataIndex: 'handlerDeptCode',
        }, */
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action'
          }
        }
      ],
      url: {
        list: '/api/erp/org/positionlevel/erpOrgPositionLevel/list',
        delete: '/api/erp/org/positionlevel/erpOrgPositionLevel/delete',
        deleteBatch: '/api/erp/org/positionlevel/erpOrgPositionLevel/deleteBatch',
        exportXlsUrl: '/api/erp/org/positionlevel/erpOrgPositionLevel/exportXls',
        importExcelUrl: 'api/erp/org/positionlevel/erpOrgPositionLevel/importExcel',
        submit: '/api/erp/org/positionlevel/erpOrgPositionLevel/submit',
        submitBatch: '/api/erp/org/positionlevel/erpOrgPositionLevel/submitBatch',
        revoke: '/api/erp/org/positionlevel/erpOrgPositionLevel/revoke',
        revokeBatch: '/api/erp/org/positionlevel/erpOrgPositionLevel/revokeBatch',
        counterTrial: '/api/erp/org/positionlevel/erpOrgPositionLevel/counterTrial',
        counterTrialBatch: '/api/erp/org/positionlevel/erpOrgPositionLevel/counterTrialBatch',
        audit: '/api/erp/org/positionlevel/erpOrgPositionLevel/audit',
        auditBatch: '/api/erp/org/positionlevel/erpOrgPositionLevel/auditBatch',
        overrule: '/api/erp/org/positionlevel/erpOrgPositionLevel/overrule',
        overruleBatch: '/api/erp/org/positionlevel/erpOrgPositionLevel/overruleBatch'
      },
      dictOptions: {},
      superFieldList: []
    }
  },
  created() {
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
  methods: {
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'string', value: 'levelName', text: '职务级别名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'levelCode', text: '职务级别代码', dictCode: '' })
      fieldList.push({ type: 'int', value: 'levelIndex', text: '职务级别序号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'status', text: '状态', dictCode: 'ENABLE_OR_DISABLE' })
      fieldList.push({ type: 'string', value: 'description', text: '描述', dictCode: '' })
      fieldList.push({ type: 'string', value: 'auditStatus', text: '审核状态', dictCode: 'audit_status' })
      fieldList.push({ type: 'string', value: 'delFlag', text: '是否已删除', dictCode: 'del_flag' })
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
